package com.xtayfjpk.zookeeper.test.master_workers;

import java.util.concurrent.CountDownLatch;

import org.apache.log4j.Logger;

public class TaskObject {
	private static final Logger LOGGER = Logger.getLogger(TaskObject.class);
	private String task;
	private String taskName;
	private boolean done = false;
	private boolean successful = false;
	private CountDownLatch latch = new CountDownLatch(1);
	
	public TaskObject(String task, String taskName) {
		this.task = task;
		this.taskName = taskName;
	}

	public void setSuccessful(boolean successful) {
		this.successful = successful;
		done = true;
		latch.countDown();
	}
	
	public void waitUntilDone() {
		try {
			latch.await();
		} catch(InterruptedException e) {
			LOGGER.warn("InterruptedException while waiting for task to get done");
		}
	}
	
	public synchronized boolean isDone() {
		return done;
	}
	
	public synchronized boolean isSuccessful() {
		return successful;
	}
	
	public String getTask() {
		return task;
	}
	public void setTask(String task) {
		this.task = task;
	}
	public String getTaskName() {
		return taskName;
	}
	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}
}
